﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="B2B.Models" %>
<script runat="server">

    //protected void Page_Load(object sender, EventArgs e)
    //{

    //}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">



</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HEAD" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="main_content" runat="server">
    
    <script type="text/javascript">
        function loadDanhMuc(maLinhVuc)
        {
            if (maLinhVuc != 0) {
                $.getJSON("/Home/DanhSachDanhMuc?id=" + maLinhVuc,
                 function (data) {
                     document.getElementById("checkCategory").innerText = "";
                     var s = '';
                     s += "<select id='MaDanhMuc' name='maDanhMuc'>";
                     for (i = 0 ; i < data.length; i++) {
                         s += "<option value='" + data[i].MaDanhMuc + "'>" + data[i].TenDanhMuc + "</option>";
                     }
                     s += "</select>";
                     $("#divDanhMuc").html(s);
                 });
            }
            else
            {
                document.getElementById("checkCategory").innerText = "Please select a item in category";
            }
        }

        function checkQuantity() {
            $("#CheckQuantity").html("");
            var quantity = document.getElementById("SoLuongCanMua");
            if (quantity.value == "") {
                $("#CheckQuantity").html("Please enter estimated order quantity");
                quantity.focus();
            }
        }

        function checkProductName() {
            $("#checkProductName").html("");
            var productname = document.getElementById("TenSanPham");
            if (productname.value == "") {
                $("#checkProductName").html("*Please enter product name");
                productname.focus();
            }
        }

        

        function CheckAndSend()
        {
         
           
            var quantity = document.getElementById("SoLuongCanMua");
            var productname = document.getElementById("TenSanPham");
            var category = document.getElementById("selProductCategory");
            var detail = document.getElementById("ChiTiet");
            var file = document.getElementById("HinhAnh");           
            if (productname.value == "") 
            {
              //  document.getElementById("checkProductName").innerHtml = "Please enter product name";
                $("#checkProductName").html("*Please enter product name");
                productname.focus();
                return false;
            }
            else
            {
                $("#checkProductName").html("");
            }
            
            if (category.value == 0) {                
                $("#checkCategory").html("*Please select a item in category");
                category.focus();
                return false;
            }
            else
            {
                $("#checkCategory").html("");
            }

            if (quantity.value == "") {
                $("#CheckQuantity").html("Please enter estimated order quantity");
                quantity.focus();
                return false;
            }
            else
            {
                $("#CheckQuantity").html("");
            }

          /*  var json = {
                TenSanPham: productname.value,
                MaDanhMuc: category.value,
                SoLuongCanMua: quantity.value,
                HinhAnh: file.files[0].name,
                FileUpload: file.value,
                MaThanhVien: 1,
                ChiTiet: detail.value,
                TinhTrang: false
            };
            $.ajax({
                url: '/Product/ProductPostBuy',
                type: 'POST',
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify(json),
                success: function (response) {
                    alert(response);
                }
            });*/

        }

        function onlyNumbers(e) {
            
            var keyword = null;
            if (window.event) {
                keyword = window.event.keyCode;
            } else {
                keyword = e.which; //NON IE;
            }

            if (keyword < 48 || keyword > 57) {
                if (keyword == 48 || keyword == 127 || keyword == 8) {
                    return;
                }
                $("#CheckQuantity").html("You have to enter number");
                return false;
            }
            $("#CheckQuantity").html("");
        }


    </script>
   
        
    <!--Bắt đầu post a buying request-->
    <div align="left">        
            <!--Bắt đầu bảng post a buying Request-->
            <form onsubmit="return CheckAndSend()" method="post" action="/Product/ProductPostBuyRequest" enctype="multipart/form-data">
                <table border="0">
                    <tr>
                        <th align="center" colspan="2"><div><h4>Tell The Supplier What You Want</h4></div></th>
                    </tr>
                    <tr>
                        <th style="width:5px"  align="right">Product Name:</th>
                        <td style="width:1000px"><input type="text" id="TenSanPham" onblur="checkProductName()" name="tenSanPham" />
                            <div id="checkProductName" style="color: red"></div>
                        </td>
                    
                    </tr>

                    <tr>
                        <th  align="right" style="width: 280px; height: 62px;">Product Category: </th>
                        <!--Tu viet group box bang javascript de chon muc mua hang-->
                    
                    
                        <td style="width: 228px; height: 62px;">
                                <select ID="selProductCategory">
                                    <option value="0">--Please select category--</option>
                                    <%foreach(var lv in (ArrayList)ViewData["linhvuc"]) 
                                      {%>                             
                                        <option onclick="loadDanhMuc('<%=((LinhVuc)lv).MaLinhVuc.ToString() %>')" value="<%=((LinhVuc)lv).MaLinhVuc.ToString() %>"><%=((LinhVuc)lv).TenLinhVuc.ToString() %></option>
                                    <%}%>
                                </select>
                                <div id="divDanhMuc"></div>
                            <div id="checkCategory" style="color: red"></div>
                                </td>
                       
                    </tr>

                     <tr>
                        <th  align="right" style="height: 91px; width: 280px;">Product Detailed Specification: </th>
                   
                        <td style="height: 91px; width: 228px;"> 
                            <textarea class="ckeditor" id="editor1" rows="5" cols="15" name="chiTiet"></textarea>
                        </td>
                      
                    </tr>

                    <tr>
                        <th  align="right" style="height: 35px; width: 280px;">Relevant Files to the Request: </th>
                        <td style="height: 35px; width: 228px;">
                              <input id="HinhAnh" name="fileUpload" style="width: 81%; height: 30px; margin-top: 5px;" type="file" />
                     
                             <input type="hidden" name="maThanhVien" value="<%=Session["maTV"].ToString() %>" />
                            <br />
                        </td>
                        
                    </tr>

                    <tr>
                        <th  align="right" style="width: 280px">Estimated Order Quantity: </th>
                        <td style="width: 228px">
                            <table>
                                <tr>
                                    <td style="height: 42px"><input type="number" onblur="checkQuantity()" id="SoLuongCanMua" onkeypress="return onlyNumbers(event)" name="soLuongCanMua" /></td>
                                </tr>
                            </table>
                            <div ID="CheckQuantity" style="color: red"></div>
                        </td>
                       
                    </tr>
                  
                   <tr>
                      <td style="width: 280px"></td>
                      <td style="width: 228px"><input type="submit" value="Send" id="send"/></td>
                    
                   </tr>

                </table>
            </form>
            <!--Kết thúc bảng post a buying Request-->
       
    </div>
    <!--Kết thúc post a buying request-->

</asp:Content>
